# -*- encoding: utf-8 -*-
"""
Some extra plugins, a few different plugins merged together
"""
import os, subprocess, sys
from setuptools import setup
from distutils.core import Extension
from Pyrex.Distutils import build_ext

os.chdir(os.path.dirname(os.path.abspath(__file__)))

__author__ = "Szentandrási István"

LANGUAGES = ()
DOMAIN = 'visual'
BASEDIR = DOMAIN+os.path.sep
PACKAGES = ['visual',]

#generate templates
if '--gen_templates' in sys.argv:
    os.system("pygettext.py -d %s -p %s %s" %
            (DOMAIN, BASEDIR+"po",
                "/*.py ".join([a.replace('.', '/') for a in PACKAGES])+"/*.py" )
            )
    sys.argv.remove('--gen_templates')


# Create mo files:
if not os.path.exists(BASEDIR+"locale"):
        os.mkdir(BASEDIR+"locale/")
for lang in LANGUAGES:
        pofile = BASEDIR+"po/" + lang + ".po"
        mofile = BASEDIR +"locale/"+ lang + "/"+DOMAIN+".mo"
        if not os.path.exists(BASEDIR+"locale/" + lang + "/"):
                os.mkdir(BASEDIR+"locale/" + lang + "/")
        print "generating", mofile
        os.system("msgfmt %s -o %s" % (pofile, mofile))

def capture(cmd):
    pipe = subprocess.Popen(cmd, shell =True, stdout= subprocess.PIPE).stdout
    retval = pipe.read().strip()
    pipe.close()
    return retval

setup(
        name = "Visualizations",
        version = "0.1",
        description = __doc__,
        author = __author__,
        packages = PACKAGES,
        ext_modules=[
            Extension("visual.xmms_vis", ["visual/xmms_vis.pyx"],
            extra_compile_args=capture("pkg-config --cflags xmms2-client gtk+-2.0").split(),
            extra_link_args=capture("pkg-config --libs xmms2-client gtk+-2.0").split()
            ),
            Extension("visual.libvisual", ["visual/libvisual.pyx"],
            extra_compile_args=capture("pkg-config --cflags libvisual-0.4").split()+['-g'],
            extra_link_args=capture("pkg-config --libs libvisual-0.4").split()
            )
            ],
        include_package_data = True,
        package_data = { 'visual': ['locale/*/*.mo', 'shaders/*.frag', 'shaders/*.vert']},
        entry_points = '''
        [etude.panels]
        Visualization = visual.visualization:Visualization
        VisualLibvisual = visual.visualization_libvisual:VisualizationLibVisual
        '''
        )

